<template>
  <div>
    <ul>
      <li v-for="(item, index) in arr" :key="index">
        {{ item }} <button @click="delFn(index)">删除</button>
      </li>
      <button @click="addFn">生成</button>
    </ul>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      arr: []
    }
  },
  methods: {
    // 添加方法
    addFn() {
      this.arr.push(Math.floor(Math.random() * 10))
    },
    // 删除方法
    delFn(index) {
      this.arr.splice(index, 1)
    }
  }
}
</script>

<style scoped>
</style>